<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品</title>
    <script src="https://www.layuicdn.com/auto/layui.js" v="2.5.6" e="layui"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/mobile/need/layer.css" rel="stylesheet">
    <link rel="stylesheet" href="static/css/style.css">
    <script src="https://cdn.bootcss.com/vue/2.5.10/vue.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="static/js/jquerysession.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <!--顶栏-->
    <div class="layui-header">
        <div class="layui-logo">购物车</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->


        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img"><span id="uname"></span>
                </a>

            </li>
            <li class="layui-nav-item"><a href="/index.html">退出登录</a></li>
        </ul>
    </div>
    <!--<header>
        <div style="float: right">
            <i  class="layui-icon  layui-anim layui-anim-rotate layui-anim-loop" style="font-size: 30px; color: #969baa;">&#xe614;</i>&nbsp; &nbsp; &nbsp;
        </div>
    </header>-->

    <div class="main" id="bc">
        <!--左栏-->
        <div class="cai">
            <ul class="cl" >
                <!--顶级分类-->
                <li v-for="vo,index in menu" :class="{hidden:vo.hidden}">
                    <a href="javascript:;"  :class="{active:vo.active}"  @click="onActive(index)">
                        <i class="layui-icon" v-html="vo.icon"></i>
                        <span v-text="vo.name"></span>
                        <i class="layui-icon arrow" v-show="vo.url.length==0">&#xe61a;</i> <i v-show="vo.active" class="layui-icon active">&#xe623;</i>
                    </a>
                    <!--子级分类-->
                    <div v-for="vo2,index2 in vo.list">
                        <a href="javascript:;" :class="{active:vo2.active}" @click="onActive(index,index2)" v-text="vo2.name"></a>
                        <i v-show="vo2.active" class="layui-icon active">&#xe623;</i>
                    </div>
                </li>
            </ul>
        </div>
        <!--右侧-->
        <div class="right">
            <form class="layui-form layui-form-pane" action="" method="post" lay-filter="dataFrm" id="dataFrm">
                <table class="layui-hide" lay-filter="Table" id="Table"></table>
                <div  id="Bar" style="display: none;" class="layui-input-block">
                    <input type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release" lay-filter="sub" lay-submit="" value="加入购物车" id="btn" lay-event="edit">
                </div>
            </form>



        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'table','form', 'laydate' ], function() {
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table;
        //绑定时间选择器


        $(function(){
            var uname = $.session.get('uname')
            $("#uname").html(uname);
        })



        table.render({
            elem: '#Table'   //渲染的目标对象
            , url: '/comm/selectcomm' //数据接口
            , title: '课程'//数据导出来的标题
            , toolbar: "#ToolBar"
            , height: 'full-350'
            , cellMinWidth: 100 //设置列的最小默认宽度
            , limits: [3, 5, 10]  //一页选择显示3,5或10条数据
            , limit: 10  //一页显示10条数据
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                console.log(this);
                console.log(JSON.stringify(res));
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
            , done: function (res, curr, count) {
            }
            , page: true  //是否启用分页
            , cols: [[   //列表数据
                {type: 'checkbox', fixed: 'left'}
                ,{field:'c_name', title:'名称', sort:true,align:'center'}
                ,{field:'category', title:'类别', align:'center'}
                ,{field:'c_price', title:'价格',align:'center'}
                ,{field:'c_show', title:'说明',align:'center'}
                ,{field:'stock', title:'库存量',align:'center'}
                , {fixed: 'right', title: '操作', toolbar: '#Bar', width: 220, align: 'center'}
            ]]
        })






            table.on("tool(Table)",function (obj){
                var data = obj.data;
                if (obj.event === 'edit') {
                    var uname = $.session.get('uname')
                    $.ajax({
                        type: "post",
                        url: "/shop/addshop",
                        data: {
                            'uname': uname,
                            'category': data.category,
                            'c_name': data.c_name,
                            'c_price': data.c_price
                        },
                        success: function (data) {
                            if (data.trim() === "1") {
                                alert("已加入购物车")
                            } else {
                                layer.msg("加入失败")
                            }
                        }
                    })
                }


            });




    })
</script>

<script src="static/js/config.js"></script>
<script src="static/js/script.js"></script>
</body>
</html>